package com.jd.controller;


import com.jd.common.AjaxResult;
import com.jd.entity.User;
import com.jd.enums.ResultEnums;
import com.jd.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpSession;

/**
 * Created by Administrator on 2017/9/19/019.
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;

    @RequestMapping("login")
    public AjaxResult login(HttpSession session, String username, String password) {
        User u = userService.login(username, password);
        if (u == null) {
            AjaxResult result = new AjaxResult(-1, "登录失败");
            System.out.println(result);
            return result;
        }
        session.setAttribute("user",u);
        return new AjaxResult(ResultEnums.SUCCESS,u);
    }
}
